<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>后台管理</title>
  <!-- 所有script封装到一起 -->
  <div th:replace="admin/common/scriptBar :: script"  ></div>
</head>
<body id="page-top">
<div id="wrapper" class="set-min-height">
  <div th:replace="admin/common/leftPageBar :: leftPage"  ></div>
  <div id="content-wrapper" class="d-flex flex-column">
    <!-- 页面开始 -->
    <div id="content">
      <div th:replace="admin/common/headPageBar :: headPage"  ></div>
      <!-- 页面内容开始 -->
      <div class="container-fluid">
        <div class="row">
        <div class="container-fluid" style="width:60% ">
            <div class="form-group">
                <span> 档案ID： </span>
                <input type="text" id="recordId"  readonly="readonly" th:value="${recordInfo['recordId']}" class="form-control form-control-user" aria-describedby="emailHelp">
            </div>
            <div class="form-group">
                <span> 上传档案的档案管理员ID： </span>
                <input type="text" id="recordAdminId" th:value="${recordInfo['recordAdminId']}" class="form-control form-control-user" aria-describedby="emailHelp">
            </div>
            <div class="form-group">
                <span> 档案名称： </span>
                <input type="text" id="recordName"  th:value="${recordInfo['recordName']}" class="form-control form-control-user" aria-describedby="emailHelp">
            </div>
            <div class="form-group">
                <span> 档案版本号： </span>
                <input type="text" id="recordVersion" th:value="${recordInfo['recordVersion']}" class="form-control form-control-user" aria-describedby="emailHelp">
            </div>
            <div class="form-group">
                <span> 档案上传时间： </span>
                <input type="text" id="recordTime" th:value="${recordInfo['recordTime']}" class="form-control form-control-user" aria-describedby="emailHelp">
            </div>
            <div class="form-group">
                <span> 目前文件：
                    <a th:href="@{'./downloadRecord/'+${recordInfo['fileHash']}}" ><span th:text="${recordInfo['fileHash']}"/></a>
                </span>
            </div>
            <div class="form-group">
                <span> 新文件：
                    <input type="file"  style="display:none" onchange="Upload()" id="FileUpload" multiple="multiple"/>
                    <input type="button" value="选择新文件" onclick="OpenFile()" class="btn btn-info"/>
                    <!-- 存放原来的fileHash以及新的fileHash -->
                    <input type="hidden" id="fileHash" th:value="${recordInfo['fileHash']}" multiple="multiple"/>
                </span>
            </div>
            <div class="form-group">
                <span> 档案描述： </span>
                <textarea id="recordDescribe" class="form-control form-control-user" th:text="${recordInfo['recordDescribe']}" aria-describedby="emailHelp"></textarea>
            </div>
            <p><input class="btn btn-primary btn-user btn-block" id="updateRecordInfo" type="button" value="确认更新"/></p>
        </div>
        </div>
      </div>
      <!-- 页面内容结束 -->

    </div>
    <!-- 页面结束 -->
    <div th:replace="admin/common/footerBar :: footer"  ></div>
  </div>
</div>
<script type="text/javascript">

    // 打开选择文件窗口
    function OpenFile() {
        $("input[type='file' ]").click();
    }
    // 上传文件
    function Upload() {
        var fileObj = document.getElementById("FileUpload").files[0]; // js 获取文件对象
        if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
            alert("请选择文件")
            return;
        }
        var formFile = new FormData();
        formFile.append("file", fileObj); //加入文件对象
        $.ajax({
            url: "./uploadFile",
            data: formFile,
            type: "post",
            dataType: "json",
            cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (result) {
                if (result.code==200) {
                    // 将刚刚上传的文件hash存在input 用于更新
                    $("input[id='fileHash']").val(result.data);
                    alert("上传成功");
                } else {
                    alert(result['msg'])
                }
            }, error: function (ex) {
                console.warn(ex)
            }
        })
    }

    // 时间选择器
    $('#recordTime').datetimepicker({
        forceParse: 0,//设置为0，时间不会跳转1899，会显示当前时间。
        language: 'zh-CN',//显示中文
        format: "yyyy-mm-dd hh:ii",
        minView: 0,//设置只显示到月份
        initialDate: new Date(),//初始化当前日期
        autoclose: true,//选中自动关闭
        todayBtn: true,//显示今日按钮
        linkField: "mirror_field",
        linkFormat: "yyyy-mm-dd hh:ii"
    });

    //更新档案记录
    $("input[id='updateRecordInfo']").click(function() {
        $.post("./updateRecordInfo",
            {
                "recordId": $("input[id='recordId']").val(),
                "recordAdminId": $("input[id='recordAdminId']").val(),
                "recordName": $("input[id='recordName']").val(),
                "recordVersion": $("input[id='recordVersion']").val(),
                "recordTime": $("input[id='recordTime']").val(),
                "recordDescribe": $("textarea[id='recordDescribe']").val(),
                "fileHash": $("input[id='fileHash']").val()
            },
            function (data) {
                alert(data['msg']);
            });
    })

</script>
</body>
</html>
